import type { DescData } from '@arco-design/web-vue/es/descriptions/interface'
import axios from 'axios'
import qs from 'query-string'

export interface PageQuery {
  current: number
  pageSize: number
  name?: string
}

export interface BrandRecord {
  id: number
  name: string | null
  sort: number
  visibility: boolean
}

export interface BrandPageRes {
  list: BrandRecord[]
  total: number
}

export interface BrandDetail extends BrandRecord {
  id: number
  name: string | null
  sort: number
  visibility: boolean
}

// 分页查询品牌
export function queryBrandPage(params: PageQuery) {
  return axios.get<BrandPageRes>('/api/brand/page', {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj)
    },
  })
}

// 获取品牌详情
export function getBrandDetail(id: number) {
  return axios.get<BrandDetail>(`/api/brand/${id}`)
}

// 创建分类
export function createBrand(data: Omit<BrandDetail, 'id'>) {
  return axios.post('/api/brand', data)
}

// 编辑分类信息
export function updateBrand(data: BrandDetail) {
  return axios.put('/api/brand', data)
}

// 启用/禁用品牌
export function toggleBrandStatus(id: number) {
  return axios.put(`/api/brand/enable/${id}`)
}

// 删除品牌
export function deleteBrand(ids: number[]) {
  return axios.delete('/api/brand', {
    data: ids,
  })
}
